package com.example.myapplication.room.entity;

import android.os.Parcel;
import androidx.room.Entity;
import android.os.Parcelable;

/**
 * @author sjh
 * @Description
 * @create 2022/3/16 10:17
 */
@Entity
public class Student1 implements Parcelable {

    //自定义的字段
    private String name;
    private int age;


    //读取和写入的顺序要一致
    protected Student1(Parcel in) {
        name = in.readString();
        age = in.readInt();
    }

    //把属性写入到Parcel对象中去
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeInt(age);
    }

    //先不管，系统扩展用的
    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Student1> CREATOR = new Creator<Student1>() {
        //创建实体对象 并且把Parcel构建好，传递给Student
        @Override
        public Student1 createFromParcel(Parcel in) {
            return new Student1(in);
        }

        //不管了
        @Override
        public Student1[] newArray(int size) {
            return new Student1[size];
        }
    };
}
